package com.neusoft.yiyang.medical.service.impl;

import com.neusoft.yiyang.common.entity.medical.CheckOrder;
import com.neusoft.yiyang.common.enums.OrderStatus;
import com.neusoft.yiyang.medical.mapper.CheckOrderMapper;
import com.neusoft.yiyang.medical.service.CheckOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckOrderServiceImpl implements CheckOrderService {

    @Autowired
    private CheckOrderMapper checkOrderMapper;

    @Override
    public void createCheckOrder(CheckOrder checkOrder) {
        checkOrderMapper.insert(checkOrder);
    }

    @Override
    public List<CheckOrder> getAllCheckOrders() {
        return checkOrderMapper.selectList(null);
    }

    @Override
    public List<CheckOrder> getCheckOrdersByCustomerId(Integer customerId) {
        return checkOrderMapper.selectByCustomerId(customerId);
    }

    @Override
    public void updateCheckOrder(CheckOrder checkOrder) {
        checkOrderMapper.updateById(checkOrder);
    }

    @Override
    public void deleteCheckOrder(Integer checkOrderId) {
        CheckOrder checkOrder = checkOrderMapper.selectById(checkOrderId);
        if (checkOrder.getFinishedTimes() > 0) {
            checkOrder.setStatus(OrderStatus.archived);
            checkOrderMapper.updateById(checkOrder);
        } else {
            checkOrderMapper.deleteById(checkOrderId);
        }
    }
}
